﻿using System.Collections;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;

namespace CoreModule.Converters
{

    [ContentProperty("Values")]
    public class NumberPlaceholderConverter : IValueConverter
    {
        public List<float> _values = new List<float>();
        public IList Values { get { return _values; } }
        public bool ContainZero { get; set; } = true;
        public string Placeholder { get; set; } = "-";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return Placeholder;
            }
            float.TryParse(value.ToString(), out var number);

            if (ContainZero && MathF.Abs(number - 0.0f) < float.Epsilon)
            {
                return Placeholder;
            }
            if (Values.Count > 0 && Values.Contains(number))
            {
                return Placeholder;
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
